//
//  ViewController.m
//  半塘晒单页面
//
//  Created by mafeng on 16/8/2.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"
#import "MyCollectionViewCell.h"
#define kCollectionViewCell @"reuse"
@interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(CGRectGetWidth(self.view.bounds) / 2 - 7.5, 100);
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    UICollectionView *listView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 320) collectionViewLayout:layout];
    [self.view addSubview:listView];
    listView.pagingEnabled = YES;
    listView.delegate = self;
    listView.dataSource = self;
    
    // 注册
    [listView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewCell];
    
    UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(140, 330, 50, 20)];
    page.currentPageIndicatorTintColor = [UIColor blackColor];
    page.pageIndicatorTintColor = [UIColor yellowColor];
    [self.view addSubview:page];
    page.numberOfPages = 2;
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewCell forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    cell.imageView.image = [UIImage imageNamed:@"user"];
    cell.label.text = @"";
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
